#include <iostream>
#include <unistd.h>

#include "Timer.h"
#include "LightsSystem.h"

class KeyBoard {
public:
    bool isHit(){
        return true;
    }
    char getKey(){
        return 'q';
    }
};


class LightMain {
public:
    LightMain()
    :_timer(1000)
    {
    }
    ~LightMain(){
    }

    void timerUpdate(){
        if(_timer.isTimeout()){
            _ls.onTimeout();
            _timer.reset();
        }
    }
    bool keyBoardUpdate(char & key){
        if(!_kb.isHit()){
            return false;
        }
        key = _kb.getKey();
        switch (key){
            case  's':
               _ls.start(); 
               break;
               /*
            case 'p':
                _ls.pause();
                break;
            case 'r':
                _ls.resume();
                break;
                */
            case 'q':
                _ls.stop();
                break;
            default:
                std::cout << "hit the key:["  << key  << "]" << std::endl;
                break;
        }
        return true;
    }

    void run(){
        for( ; ; ){
            timerUpdate();
            /*
            char key = '\0';
            if(keyBoardUpdate(key)  &&  key == 'q'){
                break;
            }*/
            usleep(100);
        }
    }

private:
    LightsSystem _ls;
    Timer _timer;
    KeyBoard _kb;
};

int main(int argc, char * argv[]){
    std::cout << "hello world" << std::endl;
    LightMain lm;
    lm.run();
    return 0;
}

